<?php

/**
 * Created by PhpStorm.
 * User: xiaotao
 * Date: 18-5-15
 * Time: 上午10:44
 */
namespace app\common\model;
use think\Model;

class UserGroup extends Model
{
    protected $table = 'group';

    // 自动转换字段
    protected $type = [
        'id'        =>  'integer',
        'status'    =>  'integer'
    ];

    // getter
    public function getAuthAttr($val) {
        if ($val) {
            $strs = explode(',', $val);
            $ids = [];
            foreach ($strs as $str) {
                $ids[] = intval($str);
            }
            return $ids;
        }
        return [];
    }

    // setter
    public function setAuthAttr($val) {
        if (is_array($val))
            return implode(',', $val);
        return $val;
    }
}